package com.tao.com.xiaowen.module.news;

import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.tao.com.xiaowen.R;

/**
 * Created by Administrator on 2016/8/17.
 */
public class NewsContentActivity extends AppCompatActivity {
    private WebView webView;
    private ProgressDialog progressDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_content);

        webView = (WebView) findViewById(R.id.webView);

        String newsContent = getIntent().getStringExtra("contentUrl");
        webView.loadUrl(newsContent);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setSupportZoom(true);//设定支持缩放
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                if (progressDialog == null) {
                    progressDialog = new ProgressDialog(NewsContentActivity.this);
                    progressDialog.setMessage("数据加载中，请稍后。。。");
                    progressDialog.show();
                    webView.setEnabled(false);// 当加载网页的时候将网页进行隐藏
                }
//                super.onPageStarted(view, url, favicon);
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (progressDialog != null && progressDialog.isShowing()) {
                    progressDialog.dismiss();
                    progressDialog = null;
                    webView.setEnabled(true);
                }
//                super.onPageFinished(view, url);
            }

        });

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
    }
}
